<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="介绍人" prop="contactIntroId">
        <!-- <el-input
          v-model="queryParams.contactIntroCode"
          placeholder="请输入介绍人"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select v-model="queryParams.contactIntroId" placeholder="请选择" clearable filterable>
          <el-option
            v-for="item in memberMap"
            :key="item.userId"
            :label="item.memberNickName"
            :value="item.userId">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="发布人" prop="contactMemberId">
        <!-- <el-input
          v-model="queryParams.contactIntroCode"
          placeholder="请输入介绍人"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select v-model="queryParams.contactMemberId" placeholder="请选择" clearable filterable>
          <el-option
            v-for="item in memberMap"
            :key="item.userId"
            :label="item.memberNickName"
            :value="item.userId">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="项目名称" prop="contactName">
        <el-input
          v-model="queryParams.contactName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-radio v-for="dict in dict.type.check_task_status" :key="dict.value" :label="dict.value">{{ dict.label }}</el-radio> -->
      <el-form-item label="任务状态" prop="contactStatus">
        <!-- <el-input
          v-model="queryParams.contactIntroCode"
          placeholder="请输入介绍人"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-select v-model="queryParams.contactStatus" placeholder="请选择" clearable>
          <el-option
            v-for="item in dict.type.debts_task_status"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>

      <!-- <el-form-item label="项目时间开始" prop="contactStartTime">
        <el-date-picker clearable
          v-model="queryParams.contactStartTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择项目时间开始">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="项目时间结束" prop="contactEndTime">
        <el-date-picker clearable
          v-model="queryParams.contactEndTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择项目时间结束">
        </el-date-picker>
      </el-form-item> -->
      <el-form-item label="欠款方" prop="contactDebtor">
        <el-input
          v-model="queryParams.contactDebtor"
          placeholder="请输入欠款方"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人" prop="contactPerson">
        <el-input
          v-model="queryParams.contactPerson"
          placeholder="请输入联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人手机号" label-width="100px" prop="contactPhone">
        <el-input
          v-model="queryParams.contactPhone"
          placeholder="请输入联系人手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <el-form-item label="地区" prop="contactRegion">
        <!-- <el-input
          v-model="queryParams.contactRegion"
          placeholder="请输入地区"
          clearable
          @keyup.enter.native="handleQuery"
        /> -->
        <el-cascader
          v-model="queryParams.contactRegion"
          :options="regions"
          :props="{
            value: 'code',
            label: 'name',
            children:'childs'
          }"
          @change="handleRegionsParamChange"></el-cascader>
      </el-form-item>
      <el-form-item label="签约时间" prop="contactSigningTime">
        <el-date-picker clearable
          v-model="queryParams.contactSigningTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择签约时间">
        </el-date-picker>
      </el-form-item>
      
      <el-form-item label="欠款金额" prop="contactDebtAmount">
        <el-input
          v-model="queryParams.contactDebtAmount"
          placeholder="请输入欠款金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <!-- <el-form-item label="审核时间" prop="contactApprovalTime">
        <el-date-picker clearable
          v-model="queryParams.contactApprovalTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择审核时间">
        </el-date-picker>
      </el-form-item> -->
      
      <!-- <el-form-item label="创建时间" prop="createdAt">
        <el-date-picker clearable
          v-model="queryParams.createdAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新时间" prop="updatedAt">
        <el-date-picker clearable
          v-model="queryParams.updatedAt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item> -->
      
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['reward:contact:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['reward:contact:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['reward:contact:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['reward:contact:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="contactList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="index" label="序号" width="50" />
      <el-table-column label="发布人" align="center" prop="introNickName" width="150" />
      <el-table-column label="项目名称" align="center" prop="contactName" width="150" />
      <el-table-column label="介绍人" align="center" prop="postedNickName" width="150" />
      
      <!-- <el-table-column label="项目时间开始" align="center" prop="contactStartTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.contactStartTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="项目时间结束" align="center" prop="contactEndTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.contactEndTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="欠款方" align="center" prop="contactDebtor" width="180"  />
      <el-table-column label="被欠款公司" align="center" prop="contactCreditor" width="180"  />
      <el-table-column label="联系人" align="center" prop="contactPerson" width="100"  />
      <el-table-column label="联系人手机号" align="center" prop="contactPhone" width="120" />
      <el-table-column label="联系人身份证号" align="center" prop="contactIdNumber" width="180" />
      <!-- <el-table-column label="联系人身份证正反面图片" align="center" prop="contactIdImage" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.contactIdImage" :width="50" :height="50"/>
        </template>
      </el-table-column> -->
      <el-table-column label="地区" align="center" prop="regionAllName" />
      <el-table-column label="签约时间" align="center" prop="contactSigningTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.contactSigningTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否诉讼" align="center" prop="contactIsLitigation">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.self_yes_no" :value="scope.row.contactIsLitigation"/>
        </template>
      </el-table-column>
      <el-table-column label="资金来源" align="center" prop="contactFundingSource">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_funding_type" :value="scope.row.contactFundingSource"/>
        </template>
      </el-table-column>
      <el-table-column label="中标金额" align="center" prop="contactBidAmount" />
      <el-table-column label="审计金额" align="center" prop="contactAuditAmount" />
      <el-table-column label="欠款金额" align="center" prop="contactDebtAmount" />
      <el-table-column label="是否完成审计" align="center" prop="contactIsAuditCompleted" width="120">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.self_yes_no" :value="scope.row.contactIsAuditCompleted"/>
        </template>
      </el-table-column>
      <el-table-column label="是否存在争议" align="center" prop="contactIsControversial" width="120">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.self_yes_no" :value="scope.row.contactIsControversial"/>
        </template>
      </el-table-column>
      <el-table-column label="情况说明" align="center" prop="contactDescription" />
      <!-- <el-table-column label="语音补充" align="center" prop="contactVoiceSupplement" /> -->
      <el-table-column label="附件" align="center" prop="contactAttachment" />
      <el-table-column label="状态" align="center" prop="contactStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.debts_task_status" :value="scope.row.contactStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="审核人" align="center" prop="contactApprover" />
      <el-table-column label="审核时间" align="center" prop="contactApprovalTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.contactApprovalTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="排序顺序" align="center" prop="contactSortOrder" />
      <el-table-column label="创建时间" align="center" prop="createdAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updatedAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updatedAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="最后更新人" align="center" prop="updatedBy" /> -->
      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width" width="220">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-reading"
            @click="openDetailHandle(scope.row)"
          >详情</el-button>
          <!-- v-if="scope.row.contactStatus === '0'" -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['reward:contact:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['reward:contact:remove']"
          >删除</el-button>
          <el-button
            v-if="scope.row.contactStatus === '0'"
            size="mini"
            type="text"
            icon="el-icon-check"
            @click="openCheckVisible(scope.row)"
          >审核</el-button>
          <el-button
            v-if="scope.row.contactStatus === '1'"
            size="mini"
            type="text"
            icon="el-icon-s-data"
            @click="openShareMoneyVisible(scope.row)"
          >分润</el-button>
          <el-button
            v-if="scope.row.contactStatus === '1'"
            size="mini"
            type="text"
            icon="el-icon-document-copy"
            @click="openShareMoneyListVisible(scope.row)"
          >分润列表</el-button>
          <el-button
            v-if="scope.row.contactStatus === '1'"
            size="mini"
            type="text"
            icon="el-icon-document-copy"
            @click="endTask(scope.row)"
          >结束任务</el-button>
         
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改临时任务发布信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="850px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="介绍码" prop="contactIntroCode">
              <el-input v-model="form.contactIntroCode" placeholder="请输入介绍人" :disabled="!!form.contactId" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="项目名称" prop="contactName">
              <el-input v-model="form.contactName" placeholder="请输入项目名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目开始时间" prop="contactStartTime">
              <el-date-picker clearable
                v-model="form.contactStartTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择项目开始时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目结束时间" prop="contactEndTime">
              <el-date-picker clearable
                v-model="form.contactEndTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择项目结束时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="欠款方" prop="contactDebtor">
              <el-input v-model="form.contactDebtor" placeholder="请输入欠款方" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="被欠款公司" prop="contactCreditor">
              <el-input v-model="form.contactCreditor" placeholder="请输入被欠款公司" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系人" prop="contactPerson">
              <el-input v-model="form.contactPerson" placeholder="请输入联系人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系人手机号" prop="contactPhone">
              <el-input v-model="form.contactPhone" placeholder="请输入联系人手机号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系人身份证号" prop="contactIdNumber">
              <el-input v-model="form.contactIdNumber" placeholder="请输入联系人身份证号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="地区" prop="contactRegion">
              <!-- <el-input v-model="form.contactRegion" placeholder="请输入地区" /> -->
              <el-cascader
                ref="regionsRef"
                v-model="form.contactRegion"
                :options="regions"
                :props="{
                  value: 'code',
                  label: 'name',
                  children:'childs'
                }"
                @change="handleRegionsChange"></el-cascader>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="联系人身份证正反面图片" prop="contactIdImage" label-width="200">
              <image-upload list-type="text" v-model="form.contactIdImage"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="签约时间" prop="contactSigningTime">
              <el-date-picker clearable
                v-model="form.contactSigningTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择签约时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否诉讼" prop="contactIsLitigation">
              <!-- <el-input v-model="form.contactIsLitigation" placeholder="请输入是否诉讼" /> -->
              <el-select v-model="form.contactIsLitigation" placeholder="是否诉讼" clearable>
                <el-option
                  v-for="dict in dict.type.self_yes_no"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- (选项，中央配套/地方自筹；省市配套) sys_funding_type -->
            <el-form-item label="资金来源" prop="contactFundingSource">
              <!-- <el-input v-model="form.contactFundingSource" placeholder="请输入资金来源(选项，中央配套/地方自筹；省市配套)" /> -->
              <el-select v-model="form.contactFundingSource" placeholder="资金来源" clearable>
                <el-option
                  v-for="dict in dict.type.sys_funding_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="中标金额" prop="contactBidAmount">
              <el-input v-model="form.contactBidAmount" placeholder="请输入中标金额" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="审计金额" prop="contactAuditAmount">
              <el-input v-model="form.contactAuditAmount" placeholder="请输入审计金额" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="欠款金额" prop="contactDebtAmount">
              <el-input v-model="form.contactDebtAmount" placeholder="请输入欠款金额" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否完成审计" prop="contactIsAuditCompleted">
              <!-- <el-input v-model="form.contactIsAuditCompleted" placeholder="请输入是否完成审计" /> -->
              <el-select v-model="form.contactIsAuditCompleted" placeholder="是否完成审计" clearable>
                <el-option
                  v-for="dict in dict.type.self_yes_no"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工程欠款是否存在争议" prop="contactIsControversial">
              <!-- <el-input v-model="form.contactIsControversial" placeholder="请输入工程欠款是否存在争议" /> -->
              <el-select v-model="form.contactIsControversial" placeholder="工程欠款是否存在争议" clearable>
                <el-option
                  v-for="dict in dict.type.self_yes_no"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="情况说明" prop="contactDescription">
              <el-input v-model="form.contactDescription" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="语音补充" prop="contactVoiceSupplement">
              <file-upload v-model="form.contactVoiceSupplement"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="附件" prop="contactAttachment">
              <!-- <el-input v-model="form.contactAttachment" placeholder="请输入附件" /> -->
              <file-upload v-model="form.contactAttachment"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="排序顺序" prop="contactSortOrder">
              <el-input v-model="form.contactSortOrder" placeholder="请输入排序顺序" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-col :span="24">
            <el-form-item label="进度说明" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <detail :visible.sync="openDetail" :record="detailInfo" />
    <check :visible.sync="openCheck" :record="checkInfo" @cancelHandle="getList" />
    <shareMoney :id="shareTaskId" :visible.sync="shareVisible" @cancelHandle="getList"></shareMoney>
    <share-money-list :id="shareTaskId" :visible.sync="shareMoneyListVisible"></share-money-list>
    
  </div>
</template>

<script>
import { listContact, getContact, delContact, addContact, updateContact } from "@/api/reward/contact";
import { memberKeyMap } from "@/api/center/member"
import detail from "./components/detail.vue";
import check from "./components/check.vue";

import shareMoney from "./components/shareMoney.vue";
import shareMoneyList from "./components/shareMoneyList.vue";
import { checkContact } from "@/api/reward/contact.js";
// import regions from "./components/regions.json"
import regions from "@/utils/regions.json"
export default {
  name: "Contact",
  dicts: ['self_yes_no', 'sys_funding_type', 'debts_task_status'],
  components: {
    detail,
    check,
    shareMoney,
    shareMoneyList
  },
  data() {
    return {
      // 打开分润列表
      shareMoneyListVisible: false,
      // 打开分润表单
      shareVisible: false,
      // 分润任务id
      shareTaskId: '',
      // 所有地区
      regions: regions,
      // 打开审核
      openCheck: false,
      // 审核详情
      checkInfo: {},
      // 打开详情
      openDetail: false,
      // 详情信息
      detailInfo: {},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 临时任务发布信息表格数据
      contactList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        contactCustomerId: null,
        contactIntroCode: null,
        contactName: null,
        contactStartTime: null,
        contactEndTime: null,
        contactDebtor: null,
        contactCreditor: null,
        contactPerson: null,
        contactPhone: null,
        contactIdNumber: null,
        contactIdImage: null,
        contactRegion: null,
        contactSigningTime: null,
        contactIsLitigation: null,
        contactFundingSource: null,
        contactBidAmount: null,
        contactAuditAmount: null,
        contactDebtAmount: null,
        contactIsAuditCompleted: null,
        contactIsControversial: null,
        contactDescription: null,
        contactVoiceSupplement: null,
        contactAttachment: null,
        contactStatus: null,
        contactApprover: null,
        contactApprovalTime: null,
        contactSortOrder: null,
        createdAt: null,
        updatedAt: null,
        updatedBy: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        contactCustomerId: [
          { required: true, message: "外键不能为空", trigger: "blur" }
        ],
        contactName: [
          { required: true, message: "项目名称不能为空", trigger: "blur" }
        ],
        contactStartTime: [
          { required: true, message: "项目时间开始不能为空", trigger: "blur" }
        ],
        contactEndTime: [
          { required: true, message: "项目时间结束不能为空", trigger: "blur" }
        ],
        contactDebtor: [
          { required: true, message: "欠款方不能为空", trigger: "blur" }
        ],
        contactCreditor: [
          { required: true, message: "被欠款公司不能为空", trigger: "blur" }
        ],
        contactPerson: [
          { required: true, message: "联系人不能为空", trigger: "blur" }
        ],
        contactPhone: [
          { required: true, message: "联系人手机号不能为空", trigger: "blur" }
        ],
        contactIdNumber: [
          { required: true, message: "联系人身份证号不能为空", trigger: "blur" }
        ],
        contactIdImage: [
          { required: true, message: "联系人身份证正反面图片不能为空", trigger: "blur" }
        ],
        contactRegion: [
          { required: true, message: "地区不能为空", trigger: "blur" }
        ],
        contactSigningTime: [
          { required: true, message: "签约时间不能为空", trigger: "blur" }
        ],
        contactIsLitigation: [
          { required: true, message: "是否诉讼不能为空", trigger: "blur" }
        ],
        contactFundingSource: [
          { required: true, message: "资金来源不能为空", trigger: "blur" }
        ],
        contactBidAmount: [
          { required: true, message: "中标金额不能为空", trigger: "blur" }
        ],
        contactAuditAmount: [
          { required: true, message: "审计金额不能为空", trigger: "blur" }
        ],
        contactDebtAmount: [
          { required: true, message: "欠款金额不能为空", trigger: "blur" }
        ],
        contactIsAuditCompleted: [
          { required: true, message: "是否完成审计不能为空", trigger: "blur" }
        ],
        contactIsControversial: [
          { required: true, message: "工程欠款是否存在争议不能为空", trigger: "blur" }
        ],
        contactStatus: [
          { required: true, message: "状态不能为空", trigger: "change" }
        ],
        contactSortOrder: [
          { required: true, message: "排序顺序不能为空", trigger: "blur" }
        ],
        createdAt: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updatedAt: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ],
        contactIntroCode: [
          { required: true, message: "介绍码不能为空", trigger: "blur" }
        ],
        contactDescription: [
        { required: true, message: "情况说明不能为空", trigger: "blur" }
        ]
      },
      // 会员列表
      memberMap: []
    };
  },
  created() {
    this.getMemberMap()
    this.getList();
  },
  methods: {
    // 获取会员列表
    getMemberMap() {
      memberKeyMap().then(res => {
        const { code, data } = res
        if (code === 200) {
          this.memberMap = data || []
        }
      })
    },
    // 打开分润列表
    openShareMoneyListVisible(record) {
      this.shareTaskId = record.contactId
      this.shareMoneyListVisible = true
    },
    // 打开分润窗口
    openShareMoneyVisible(record) {
      this.shareTaskId = record.contactId
      this.shareVisible = true
    },
    // 打开审核
    openCheckVisible(record) {
      this.openCheck = true
      this.checkInfo = record
    },
    // 打开详情
    openDetailHandle(record) {
      this.detailInfo = record
      this.openDetail = true
    },
    /** 查询临时任务发布信息列表 */
    getList() {
      this.loading = true;
      listContact(this.queryParams).then(response => {
        this.contactList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        contactId: null,
        contactCustomerId: null,
        contactIntroCode: null,
        contactName: null,
        contactStartTime: null,
        contactEndTime: null,
        contactDebtor: null,
        contactCreditor: null,
        contactPerson: null,
        contactPhone: null,
        contactIdNumber: null,
        contactIdImage: null,
        contactRegion: "410102",
        contactSigningTime: null,
        contactIsLitigation: null,
        contactFundingSource: null,
        contactBidAmount: null,
        contactAuditAmount: null,
        contactDebtAmount: null,
        contactIsAuditCompleted: null,
        contactIsControversial: null,
        contactDescription: null,
        contactVoiceSupplement: null,
        contactAttachment: null,
        contactStatus: null,
        contactApprover: null,
        contactApprovalTime: null,
        contactSortOrder: 50,
        createdAt: null,
        updatedAt: null,
        updatedBy: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.contactId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加清欠业务";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const contactId = row.contactId || this.ids
      getContact(contactId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改清欠业务";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.contactId != null) {
            updateContact(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addContact(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const contactIds = row.contactId || this.ids;
      this.$modal.confirm('是否确认删除临时任务发布信息编号为"' + contactIds + '"的数据项？').then(function() {
        return delContact(contactIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('reward/contact/export', {
        ...this.queryParams
      }, `contact_${new Date().getTime()}.xlsx`)
    },
    // 选择地区
    handleRegionsChange(e) {
      console.log(e)
      if (e.length > 0) {
        this.form.contactRegion = e[e.length - 1]
        const regionCheckNode = this.$refs.regionsRef.getCheckedNodes()
        this.form.regionAllName = regionCheckNode[0].pathLabels.join(',')
        console.log(this.form.contactRegion)
        console.log(this.form.regionAllName)
      } else {
        this.form.contactRegion = ''
        this.form.regionAllName = ''
      }
    },
    handleRegionsParamChange(e) {
      if (e.length > 0) {
        this.queryParams.contactRegion = e[e.length - 1]
      } else {
        this.queryParams.contactRegion = ''
      }
    },
    // 结束任务
    endTask(record) {
      const postData = {
        contactId: record.contactId,
        contactStatus: 2,
      }
      this.$modal.confirm('是否确认结束任务名称为"' + record.contactName + '"的数据项？').then(function() {
        return checkContact(postData);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("任务已结束");
      }).catch(() => {});
    }
  }
};
</script>
